﻿@using Xms.Abp.Data
@namespace Xms.Abp.Components

@inherits AntDomComponentBase
@typeparam TService
@typeparam TPagingListViewModel
@typeparam TKey
@typeparam TPagedParameter
@typeparam TDetailsViewModel
@typeparam TCreateViewModel
@typeparam TUpdateViewModel
@typeparam TDetailsView
@typeparam TCreateView
@typeparam TUpdateView
@typeparam TSelf

<PageWrapper Class="@("ant-list-page " + Class)" Id="Id" RefBack="RefBack" Style="@Style">
    <Breadcrumb>
        <Breadcrumb>
            <BreadcrumbItem>@ModuleName</BreadcrumbItem>
            @if (!string.IsNullOrWhiteSpace(SubModuleName))
            {
            <BreadcrumbItem>@SubModuleName</BreadcrumbItem>
            }
            <BreadcrumbItem>@Title</BreadcrumbItem>
        </Breadcrumb>
    </Breadcrumb>
    <Content>
        <Row>
            <AntDesign.Col Span="17">
                @if (SearchContent != null)
                {
                    @SearchContent(PagedParameter)
                }
                @if (!DisableFilter)
                {
                <Search Class="page-search" Placeholder="@SearchFilterPlaceholder" AllowClear @bind-Value="PagedParameter.Filter" WrapperStyle="width: 300px;" EnterButton="@("搜索")" OnSearch="OnSearchClickAsync" />
                }
            </AntDesign.Col>
            <AntDesign.Col Span="7" Style="text-align:right;">
                @if (ToolborContent != null)
                {
                    @ToolborContent
                }
                else
                {
                    @if (Creatable && HasCreatePermission)
                    {
                        <Button Icon="plus" Type="@ButtonType.Primary" OnClick='OnCreateActionClickAsync'>创建</Button>
                    }
                    @if (Exportable && HasExportPermission)
                    {
                        <Button Icon="export" OnClick='OnExportActionClickAsync'>导出数据</Button>
                    }
                    @if (DeleteManyable && (DeleteManyableFunc == null || DeleteManyableFunc(SelectedRows)) && HasDeleteManyPermission
                        || Importable && HasImportPermission
                        || ToolbarMoreActions != null)
                    {
                        <DropdownButton>
                            <Overlay>
                                <Menu>
                                    @if (DeleteManyable && (DeleteManyableFunc == null || DeleteManyableFunc(SelectedRows)) && HasDeleteManyPermission)
                                    {
                                        <MenuItem OnClick='OnDeleteManyActionClickAsync'>批量删除</MenuItem>
                                    }
                                    @if (Importable && HasImportPermission)
                                    {
                                        <MenuItem OnClick='OnDownloadTemplateActionClickAsync'>下载导入模板</MenuItem>
                                        <Upload Name="files" Action="@AppService.ImportUrl" OnCompleted="OnUploadCompletedAsync">
                                            <MenuItem Icon="upload">导入数据</MenuItem>
                                        </Upload>
                                    }
                                    @if (ToolbarMoreActions != null)
                                    {
                                        @ToolbarMoreActions
                                    }
                                </Menu>
                            </Overlay>
                            <Unbound>
                                批量操作
                            </Unbound>
                        </DropdownButton>
                    }
                }
                <br/>
            </AntDesign.Col>
        </Row>
        <br />
            @*RowExpandable="IsTableRowExpandable()"*@
        <Table
            TItem="TPagingListViewModel"
            RowExpandable="RowExpandable"
            Bordered="true"
            Size="TableSize.Small"
            DataSource="@DataSource"
            Loading="@PagingLoading"
            SelectedRows="@SelectedRows"
            @bind-Total="TotalCount"
            @bind-PageIndex="PagedParameter.PageIndex"
            @bind-PageSize="PagedParameter.PageSize"
            OnChange="HandleTableChange"
            ExpandTemplate="ExpandTemplate"
            TreeChildren="@TreeChildren"
            ScrollX="@ScrollX"
            Style="width:100%"
            RemoteDataSource
        >
            <RowTemplate>
                <Selection Key="@(context.Id.ToString())" Disabled="IsSelectionDisabled(context)" Fixed="left" Width="32" />
                @if (Columns != null)
                {
                    @Columns(context)
                }
                else
                {
                    foreach(var column in GetTableColumnInfos())
                    {
                    <Column TData="object" DataIndex="@column.Name">
                        <ChildContent>
                            @column.GetValue(context)
                        </ChildContent>
                    </Column>
                    }
                }
                @if (context is IHasChildren<TPagingListViewModel> && CreateChildable && (CreateChildableFunc == null || CreateChildableFunc(context)) && HasCreatePermission
                    || Detailsable && (DetailsableFunc == null || DetailsableFunc(context)) && HasDetailsPermission
                    || Updatable && (UpdatableFunc == null || UpdatableFunc(context)) && HasUpdatePermission
                    || Deletable && (DeletableFunc == null || DeletableFunc(context)) && HasDeletePermission
                    || SubmitReviewable && (SubmitReviewableFunc == null || SubmitReviewableFunc(context)) && HasSubmitReviewPermission
                    || Reviewable && (ReviewableFunc == null || ReviewableFunc(context)) && HasReviewPermission
                    || RowMoreActions != null)
                {
                <ActionColumn Title="操作" Fixed="right" Width="@ActionColumnWidth">
                    <Space>
                    @if (Columns != null
                        && context is IEditingInRow e
                        && (e.IsCreating || e.IsUpdating))
                    {
                        if (e.IsCreating)
                        {
                        <SpaceItem>
                            <Button
                                Size="small"
                                Type="@ButtonType.Primary"
                                OnClick='_ => OnSaveCreateActionClickAsync(context)'
                                @bind-Loading="e.IsSaving"
                                @bind-Disabled="e.IsSaving"
                            >保存</Button>
                        </SpaceItem>
                        <SpaceItem>
                            <Popconfirm
                                Title="@("确定要取消吗？")"
                                OnConfirm='_ =>  OnCancelCreateActionClickAsync(context)'
                                OkText="确定"
                                CancelText="取消"
                            >
                                <Button Size="small">取消</Button>
                            </Popconfirm>
                        </SpaceItem>
                        }
                        else
                        {
                        <SpaceItem>
                            <Button
                                Size="small"
                                Type="@ButtonType.Primary"
                                OnClick='_ => OnSaveUpdateActionClickAsync(context)'
                                @bind-Loading="e.IsSaving"
                                @bind-Disabled="e.IsSaving"
                            >保存</Button>
                        </SpaceItem>
                        <SpaceItem>
                            <Popconfirm
                                Title="@("确定要取消吗？")"
                                OnConfirm='_ => OnCancelUpdateActionClickAsync(context)'
                                OkText="确定"
                                CancelText="取消"
                            >
                                <Button Size="small">取消</Button>
                            </Popconfirm>
                        </SpaceItem>
                        }
                    }
                    else
                    {
                        @if (context is IHasChildren<TPagingListViewModel> && CreateChildable && (CreateChildableFunc == null || CreateChildableFunc(context)) && HasCreatePermission)
                        {
                        <SpaceItem>
                            <Button
                                Size="small"
                                Type="@ButtonType.Primary"
                                Ghost
                                OnClick='_=> OnCreateActionClickAsync(context)'
                            >创建</Button>
                        </SpaceItem>
                        }
                        @if (Detailsable && (DetailsableFunc == null || DetailsableFunc(context)) && HasDetailsPermission)
                        {
                        <SpaceItem>
                            <Button
                                Size="small"
                                OnClick='_ => OnDetailsActionClickAsync(context)'
                            >详情</Button>
                        </SpaceItem>
                        }
                        @if (Updatable && (UpdatableFunc == null || UpdatableFunc(context)) && HasUpdatePermission)
                        {
                            @if (context is not IHasReview reviewModel || reviewModel.ReviewStatus == ReviewStatus.Draft || reviewModel.ReviewStatus == ReviewStatus.Reject)
                            {
                        <SpaceItem>
                            <Button
                                Size="small"
                                Type="@ButtonType.Primary"
                                OnClick='_=> OnUpdateActionClickAsync(context)'
                            >修改</Button>
                        </SpaceItem>
                            }
                        }
                        @if (SubmitReviewable && (SubmitReviewableFunc == null || SubmitReviewableFunc(context)) && HasSubmitReviewPermission)
                        {
                            @if (context is IHasReview reviewModel && reviewModel.ReviewStatus == ReviewStatus.Draft)
                            {
                        <SpaceItem>
                            <Popconfirm
                                Title="@("确定要提交审核吗？")"
                                OnConfirm='_ => OnSubmitReviewActionClickAsync(context)'
                                OkText="确定"
                                CancelText="取消"
                            >
                                <Button Size="small" Type="@ButtonType.Primary" Ghost>提交审核</Button>
                            </Popconfirm>
                        </SpaceItem>
                            }
                        }
                        @if (Reviewable && (ReviewableFunc == null || ReviewableFunc(context)) && HasReviewPermission)
                        {
                            @if (context is IHasReview reviewModel && reviewModel.ReviewStatus == ReviewStatus.Reviewing && reviewModel.ReviewerNo == CurrentUser.UserName)
                            {
                        <SpaceItem>
                            <Button
                                Size="small"
                                Type="@ButtonType.Primary"
                                OnClick='_=> OnReviewActionClickAsync(context)'
                                Ghost
                            >审核</Button>
                        </SpaceItem>
                            }
                        }
                        @if (Deletable && (DeletableFunc == null || DeletableFunc(context)) && TreeChildren(context).Count() <= 0 && HasDeletePermission)
                        {
                            @if (context is not IHasReview reviewModel || reviewModel.ReviewStatus == ReviewStatus.Draft || reviewModel.ReviewStatus == ReviewStatus.Reject)
                            {
                        <SpaceItem>
                            <Popconfirm
                                Title="@("确定要删除吗？")"
                                OnConfirm='_ => OnDeleteActionClickAsync(context)'
                                OkText="确定"
                                CancelText="取消"
                            >
                                <Button Size="small" Danger>删除</Button>
                            </Popconfirm>
                        </SpaceItem>
                            }
                        }
                        @if (RowMoreActions != null && RowMoreActionsFunc != null && RowMoreActionsFunc(context))
                        {
                        <SpaceItem>
                            <DropdownButton Size="small">
                                <Overlay>
                                    <Menu>
                                    @RowMoreActions(context)
                                    </Menu>
                                </Overlay>
                                <Unbound Context="ctx">
                                    更多操作
                                </Unbound>
                            </DropdownButton>
                        </SpaceItem>
                        }
                    }
                    </Space>
                </ActionColumn>
                }
            </RowTemplate>
            <PaginationTemplate>
                <br/>
                <Pagination
                    ShowTotal="PagingShowTotal()"
                    DefaultCurrent="1"
                    @bind-Total="TotalCount"
                    @bind-Current="PagedParameter.PageIndex"
                    @bind-PageSize="PagedParameter.PageSize"
                    OnChange="OnPagingChangeAsync"
                    TotalBoundaryShowSizeChanger="20"
                    PageSizeOptions="@(new[]{10,15,20,30,50,100})"
                    ShowQuickJumper
                    ShowSizeChanger>
                    <GoButton>
                        @*跳至
                        <AntDesign.InputNumber TValue="int" @bind-Value="PagedParameter.PageIndex" Style="width:52px;border:none;" />
                        页*@
                        <Button
                            Style="margin-top:2px;margin-left:8px;"
                            OnClick="OnGoClickAsync"
                            HtmlType="submit"
                        >跳转</Button>
                    </GoButton>
                </Pagination>
            </PaginationTemplate>
        </Table>
    </Content>
</PageWrapper>
<style>
    .ant-list-page .ant-pro-page-container-main .ant-pro-page-container-row{
        display:block!important;
    }
    .ant-table.ant-table-small, .ant-table.ant-table-small .ant-btn-sm {
        font-size: 12px!important;
    }
    .ant-table.ant-table-small .ant-btn-sm {
        height: 22px!important;
        padding: 0 4px!important;
    }
    .ant-table.ant-table-small .ant-table-footer, .ant-table.ant-table-small .ant-table-tbody>tr>td {
        padding: 4px!important;
    }
    .ant-table.ant-table-small .ant-table-measure-row {
        display:none;
    }
</style>
